<?php

namespace app\common\validate;

use think\Validate;

class Admin extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'    =>    ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'nickname|昵称' => 'require',
        'oldpass|原密码' => 'require',
        'username|管理员账号' => 'require|unique:Admin',
        'password|密码' => 'require',
        'conpass|确认密码' => 'require|confirm:password',
        'email|邮箱' => 'require|email|unique:Admin'
    ];

    //登陆验证场景
    public function sceneLogin()
    {
        $this->only(['username', 'password'])->remove('username', 'unique');
    }

    //注册验证场景
    public function sceneRegister()
    {
        return $this->only(['nickname', 'username', 'password', 'conpass', 'email']);
    }

    //添加场景
    public function sceneAdd(){
        $this->only(['nickname', 'username', 'password', 'conpass', 'email']);
    }

    public function sceneEdit(){
        $this->only(['nickname', 'oldpass', 'password', 'conpass']);
    }

    /**
     * 定义错误信息
     * 格式：'字段名.规则名'    =>    '错误信息'
     *
     * @var array
     */
    protected $message = [
        'conpass.confirm' => '两次密码不一致！'
    ];
}
